<!DOCTYPE html>
<html>
<head>
<title></title>
<!-- For-Mobile-Apps -->
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />
	<script type="text/javascript" src="${request.contextPath}/skins/js/jquery.min.js"></script>
 	<link rel="stylesheet" href="${request.contextPath}/skins/css/login_style.css" type="text/css" media="all" />
	<link rel="stylesheet" href="${request.contextPath}/skins/layui/css/layui.css" />
	<script type="text/javascript" src="${request.contextPath}/skins/layui/layui.all.js"></script>
	<!-- 自己写的常用js -->
	<script type="text/javascript" src="${request.contextPath}/skins/js/common.js"></script>
	<!-- 自己写的常用css -->
	<link rel="stylesheet" href="${request.contextPath}/skins/css/my_common.css">
	<!--md5加密-->
	<script type="text/javascript" src="${request.contextPath}/skins/js/jquery.md5.js"></script>
</head>
<body>
<div class="container" id="login_div">
	<h1>authstr</h1>
	<div class="signin">
		<div class="title_info" style="margin-top: 0px;margin-bottom: 20px;color: white" >登录</div>
     	<form id="login" action="login"   method="post">
	      	<input type="text" class="inp user" value="" name="account" id="account_login" placeholder="账号"/>
	      	<input type="password" class="inp pass" id="password" value="" placeholder="密码"/>
			<input type="hidden" class="inp pass" name="password" id="password_hide" value=""/>
          	<input type="submit" value="登录" />
			<div class="footer" style="float: left ;margin-top: 10px;cursor: pointer;">
				<a style="color: #ECF0F1;" onclick="func.forget_the_password()"> 忘记密码</a>
			</div>
			<div class="footer" style="float: right;margin-top: 10px;cursor: pointer;">
				<a style="color: #ECF0F1;" onclick="func.register_page()" > 没有账号?点击注册</a>
			</div>
	 	</form>
	</div>
</div>

<div class="container" id="register_div" style="display:none;">
	<h1>authstr</h1>
	<div class="signin">
		<div class="title_info" style="margin-top: 0px;margin-bottom: 20px;color: white" >注册</div>
		<form id="register">
			<input type="text" class="inp user" name="account" id="account" value="" placeholder="账号"/>
			<input type="password" class="inp pass" id="pwd" name="password" value="" placeholder="密码"/>
			<input type="password" class="inp pass" id="affirmPwd" value="" placeholder="确认密码"/>
			<input type="text" class="inp email" id="email" name="email" value="" placeholder="邮箱"/>
			<input type="submit"  value="注册" />
			<div class="footer" style="float: right;margin-top: 10px;cursor: pointer;">
				<a style="color: #ECF0F1;" onclick="func.login_page()" > 已有账号?点击登录</a>
			</div>
		</form>
	</div>
</div>
<div class="footer">
     <p>Copyright &copy; 2019 233333333333333333  <a href="http://authstr.cn">authstr.cn</a></p>
</div>
<script>

	// $.ajaxSetup({ //发送请求前触发
	// 	beforeSend: function (xhr) { //可以设置自定义标头
	// 		console.log("ajax beforesend token:", "111")
	// 		xhr.setRequestHeader('token', "111");
	// 	}
	// })

	var is_register="${is_register!?html}";
	var skip_path="${skip_path!?html}";
	var func = {
		register: function () {
			var para = tool.paraArrayToLiteral($("#register").serializeArray());
			if (para.password != '') {
				para.password = $.md5(para.password);
			}
			$.post("${request.contextPath}/register", para, function (o) {
				if (o.code == 0) {
					layer.msg(o.message);
					func.login_page();
					// location.href = document.referrer;
				} else {
					layer.alert(o.message, {
						skin: 'layui-layer-molv' //样式类名
						, closeBtn: 0
						, title: "错误提示"
					});
				}
			});
		},
		login: function () {
			var para = tool.paraArrayToLiteral($("#login").serializeArray());
			if (para.password != '') {
				para.password = $.md5(para.password);
			}
			if(!tool.isEmpty(skip_path)){
				para["skip_path"] =skip_path;
			}

			$.post("${request.contextPath}/loginVail", para, function (o) {
				if (o.code == 0) {
					layer.msg(o.message);
					setTimeout(function () {
						window.location="${request.contextPath}"+o.data
					},500)
					// window.location=o.path
					// location.href = document.referrer;
				} else {
					layer.alert(o.message, {
						skin: 'layui-layer-molv' //样式类名
						, closeBtn: 0
						, title: "错误提示"
					});
				}
			});
		},
		forget_the_password:function(){
			layer.msg('功能开发中!');
		},
		register_page:function(){
			$("#login_div").hide();
			$("#register_div").show();
		},
		login_page:function(){
			$("#login_div").show();
			$("#register_div").hide();
		},
		load: function () {
			$.getJSON("${request.contextPath}/user/getById", {id: $("#id").val()}, function (o) {
				if (o.code == 0) {
					$("#form1").setFormValues(o.data);
				}
			});
		}
	}
	$(function () {

		if(is_register=="1"){
			func.register_page();
		}

		var msg='${tips!?html}';
		if(msg!=''){
			layer.msg(msg);
		}
		$("#register").submit(function(e){
			//阻止form表单默认提交
			event.preventDefault()
			if($("#account").val()==""){
				layer.msg('请输入用户名!');
				return false;
			}
			if($("#pwd").val()==""){
				layer.msg('请输入密码!');
				return false;
			}
			if($("#affirmPwd").val()==""){
				layer.msg('请确认密码!');
				return false;
			}
			if($("#pwd").val()!=$("#affirmPwd").val()){
				layer.msg('两次密码输入不一致!');
				return false;
			}
			if($("#email").val()==""){
				layer.msg('请输入邮箱!');
				return false;
			}
			func.register();
			return false;
		});
		$("#login").submit(function(e){
			//阻止form表单默认提交
			// event.preventDefault()
			if($("#account_login").val()==""){
				layer.msg('请输入用户名!');
				return false;
			}

			var password=$("#password").val();
			console.log(password);
			if(password==""){
				layer.msg('请输入密码!');
				return false;
			}
			$("#password_hide").val($.md5(password))
			return true;
		});
	});
	// addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); }
</script>

</body>
</html>